package com.app.service.impl;


import com.app.mapper.StreetMapper;
import com.app.mapper.TrainInvestigateMapper;
import com.app.model.ConfigModel;
import com.app.model.StreetModel;
import com.app.model.TrainEnrollModel;
import com.app.model.TrainInvestigateModel;
import com.app.service.ConfigService;
import com.app.service.StreetService;
import com.app.service.TrainInvestigateService;
import com.app.util.StringTool;
import com.app.vo.TrainInvestigateVo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * @Description:肃北县县域劳动力2024年补贴性职业技能培训意愿调查问卷
 * @Author: N
 * @Date: 2022年11月24日 10点29分
 */
@Service
public class TrainInvestigateServiceImpl implements TrainInvestigateService {
    @Autowired
    TrainInvestigateMapper trainInvestigateMapper;
    @Autowired
    ConfigService configService;
    @Override
    public TrainInvestigateVo getPageByModel(TrainInvestigateModel model) {
        QueryWrapper<TrainInvestigateModel> queryWrapper = new QueryWrapper<>();
        if(model!=null)
        {
            if(StringTool.isNotEmpty(model.getName()))
            {
                queryWrapper.like("name",model.getName());
            }
            if(StringTool.isNotEmpty(model.getType()))
            {
                queryWrapper.eq("type",model.getType());
            }
            if(StringTool.isNotEmpty(model.getIsTrain()))
            {
                queryWrapper.eq("is_train",model.getIsTrain());
            }
            if(StringTool.isNotEmpty(model.getIsNeed()))
            {
                queryWrapper.eq("is_need",model.getIsNeed());
            }
        }
        queryWrapper.orderByDesc("crt_time");
        Page<TrainInvestigateModel> page = new Page<>();
        page.setCurrent(model.getPage());
        page.setSize(model.getLimit());
        Page<TrainInvestigateModel> jobFairSceneModelPage = trainInvestigateMapper.selectPage(page,queryWrapper);
        for (int i = 0; i < jobFairSceneModelPage.getRecords().size(); i++) {
            if(jobFairSceneModelPage.getRecords().get(i).getIsLocal().equals("是"))
            {
                ConfigModel configModel = configService.getModelById(Integer.valueOf(jobFairSceneModelPage.getRecords().get(i).getLocalAddress()));
                jobFairSceneModelPage.getRecords().get(i).setLocalAddressText(configModel.getName());
            }

        }
        TrainInvestigateVo vo = new TrainInvestigateVo();
        vo.setCount((int) jobFairSceneModelPage.getTotal());
        vo.setList(jobFairSceneModelPage.getRecords());
        return vo;
    }
}
